﻿<template>
  <div>
    <p style="font-size: 30px;font-weight: 700;">学生客户公海策略设置</p>
    <div class="group-box">
      <el-row>
        <el-col :span="12">
          <span style=" font-size: 24px;font-weight: 700;"
            >是否允许个人领用公海客户：</span
          >
        </el-col>
        <el-col :span="12">
          <el-radio v-model="radio" label="1" size="medium">是</el-radio>
          <el-radio v-model="radio" label="2" size="medium">否</el-radio>
        </el-col>
      </el-row>
      <div style=" margin-top: 2%">
        <el-row>
          <el-col :span="12">
            <span style=" font-size: 24px; font-weight: 700;"
              >是否自动回归公海：</span
            >
          </el-col>
          <el-col :span="12">
            <el-radio v-model="auto" label="1" size="medium">是</el-radio>
            <el-radio v-model="auto" label="2" size="medium">否</el-radio>
          </el-col>
        </el-row>
      </div>
      <div class="input-box" v-if="auto == 1">
        <el-row>
          <el-col :span="12">
            <div class="tit">
              <span>自动回归期限：</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="input-box-c">
              <el-row>
                <el-col :span="6">
                  <span class="input-box-c-tit">A类客户：</span>
                </el-col>
                <el-col :span="6">
                  <el-input v-model="aUser"></el-input>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="6">
                  <span class="input-box-c-tit">B+类客户：</span>
                </el-col>
                <el-col :span="6">
                  <el-input v-model="bUser"></el-input>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="6">
                  <span class="input-box-c-tit">B-类客户：</span>
                </el-col>
                <el-col :span="6">
                  <el-input v-model="b2User"></el-input>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="6">
                  <span class="input-box-c-tit">C类客户：</span>
                </el-col>
                <el-col :span="6">
                  <el-input v-model="cUser"></el-input>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="6">
                  <span style="margin-top:5%;display:inline-block"
                    >D类客户：</span
                  >
                </el-col>
                <el-col :span="6">
                  <el-input v-model="dUser"></el-input>
                </el-col>
              </el-row>
            </div>
          </el-col>
        </el-row>
      </div>
      <div style="text-align: left; margin-top: 2%">
        <div class="input-box-c">
          <el-row>
            <el-col :span="9">
              <span style=" font-size: 24px; font-weight: 700;"
                >个人私海客户A类数量限制：</span
              >
            </el-col>
            <el-col :span="7">
              <el-input style="margin-left:40%" v-model="abUser"></el-input>
            </el-col>
          </el-row>
        </div>
      </div>
      <div style="margin-top: 2%;">
        <KtButton
          :label="$t('action.close')"
          perms="true"
          type="primary"
          size="medium"
          style="margin-right: 2%;"
          @click="closeSelectedTag()"
        ></KtButton>
        <KtButton
          :label="$t('action.save')"
          perms="true"
          type="primary"
          size="medium"
          style="margin-top: 2%; "
          @click="saveDepart"
        ></KtButton>
      </div>
    </div>
  </div>
</template>

<script>
import PersonalTable from "@/views/Core/PersonalTable";
import DepartmentTable from "@/views/Core/DepartmentTable";
import KtButton from "@/views/Core/KtButton";
export default {
  name: "school",
  components: {
    KtButton
  },
  data() {
    return {
      radio: "",
      auto: "",
      selectedTag: this.$route.path,
      listCustomerAutomaticAssignStrategy: [],
      aUser: "",
      bUser: "",
      b2User: "",
      cUser: "",
      dUser: "",
      eUser: "",
      abUser: ""
    };
  },
  computed: {
    visitedViews() {
      return this.$store.state.tagsview.visitedViews;
    }
  },
  watch: {
    visible(value) {
      if (value) {
        document.body.addEventListener("click", this.closeMenu);
      } else {
        document.body.removeEventListener("click", this.closeMenu);
      }
    }
  },
  methods: {
    // 获取配置信息

    getConfig() {
      //是否允许个人领用公海客户
      this.$api.student
        .strategyConfigQueryConfig({
          names: "ALLOW_RECIPIENTS_SEA_CUSTOMER",
          type: 1
        })
        .then(res => {
          this.radio = res.customerAssignConfig[0].value;
        });
      //是否自动回归公海
      this.$api.student
        .strategyConfigQueryConfig({
          names: "HQ_AUTOWARE_REURN_SEA",
          type: 1
        })
        .then(res => {
          this.auto = res.customerAssignConfig[0].value;
        });
      // 获取A类客户客户自动回归期限
      this.$api.student
        .strategyConfigQueryConfig({
          names: "HQ_A_CUSTOMER_AUTOWARE_RETURN_SEA_CYCLE",
          type: 1
        })
        .then(res => {
          this.aUser = res.customerAssignConfig[0].value;
        });
      // 获取B类客户客户自动回归期限
      this.$api.student
        .strategyConfigQueryConfig({
          names: "HQ_B_CUSTOMER_AUTOWARE_RETURN_SEA_CYCLE",
          type: 1
        })
        .then(res => {
          this.bUser = res.customerAssignConfig[0].value;
        });
      // 获取B-类用户
      this.$api.student
        .strategyConfigQueryConfig({
          names: "HQ_B2_CUSTOMER_AUTOWARE_RETURN_SEA_CYCLE",
          type: 1
        })
        .then(res => {
          this.b2User = res.customerAssignConfig[0].value;
        });
      // 获取C类客户客户自动回归期限
      this.$api.student
        .strategyConfigQueryConfig({
          names: "HQ_C_CUSTOMER_AUTOWARE_RETURN_SEA_CYCLE",
          type: 1
        })
        .then(res => {
          this.cUser = res.customerAssignConfig[0].value;
        });
      // 获取D类客户客户自动回归期限
      this.$api.student
        .strategyConfigQueryConfig({
          names: "HQ_D_CUSTOMER_AUTOWARE_RETURN_SEA_CYCLE",
          type: 1
        })
        .then(res => {
          this.dUser = res.customerAssignConfig[0].value;
        });
      // 个人私海客户A类数量限制：
      this.$api.student
        .strategyConfigQueryConfig({
          names: "HQ_A_CUSTOMER_NUM_LIMIT",
          type: 1
        })
        .then(res => {
          this.abUser = res.customerAssignConfig[0].value;
        });
    },
    saveDepart() {
      this.$confirm("确定提交信息？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let aa = [];
        let bb = [];
        let cc = [];
        let customerAssignConfigList = Object.assign({}, this.auto);
        let customerAssignConfigList2 = Object.assign({}, this.radio);
        aa.push(customerAssignConfigList);
        bb.push(customerAssignConfigList2);
        aa.forEach(item => {
          item.value = item[0];
          item.name = "HQ_AUTOWARE_REURN_SEA";
        });
        bb.forEach(item => {
          item.value = item[0];
          item.name = "ALLOW_RECIPIENTS_SEA_CUSTOMER";
        });
        this.$api.student
          .strategyConfigSetConfig({
            customerAssignConfigList: aa,
            type: 1
          })
          .then(res => {
            if (res.result == 2) {
              this.$message({
                message: res.msg,
                type: "error"
              });
            } else {
              this.$message({
                message: res.msg,
                type: "success"
              });
            }
          });
        this.$api.student
          .strategyConfigSetConfig({
            customerAssignConfigList: bb,
            type: 1
          })
          .then(res => {
            if (res.result == 2) {
              this.$message({
                message: res.msg,
                type: "error"
              });
            } else {
              this.$message({
                message: res.msg,
                type: "success"
              });
            }
          });
        // 提交A类用户
        let customerAssignConfigListA = [
          {
            name: "HQ_A_CUSTOMER_AUTOWARE_RETURN_SEA_CYCLE",
            value: this.aUser
          }
        ];
        // 提交B类用户
        let customerAssignConfigListB = [
          {
            name: "HQ_B_CUSTOMER_AUTOWARE_RETURN_SEA_CYCLE",
            value: this.bUser
          }
        ];
        // 提交B-类用户
        let customerAssignConfigListB2 = [
          {
            name: "HQ_B2_CUSTOMER_AUTOWARE_RETURN_SEA_CYCLE",
            value: this.b2User
          }
        ];
        // 提交C类用户
        let customerAssignConfigListC = [
          {
            name: "HQ_C_CUSTOMER_AUTOWARE_RETURN_SEA_CYCLE",
            value: this.cUser
          }
        ];
        // 提交D类用户
        let customerAssignConfigListD = [
          {
            name: "HQ_D_CUSTOMER_AUTOWARE_RETURN_SEA_CYCLE",
            value: this.dUser
          }
        ];
        // 个人私海客户A类数量限制：
        let customerAssignConfigListAB = [
          {
            name: "HQ_A_CUSTOMER_NUM_LIMIT",
            value: this.abUser
          }
        ];
        this.$api.student
          .strategyConfigSetConfig({
            customerAssignConfigList: customerAssignConfigListAB,
            type: 1
          })
          .then(res => {
            if (res.result == 2) {
              this.$message({
                message: res.msg,
                type: "error"
              });
            } else {
              this.$message({
                message: res.msg,
                type: "success"
              });
            }
          });
        if (this.auto == 1) {
          this.$api.student
            .strategyConfigSetConfig({
              customerAssignConfigList: customerAssignConfigListA,
              type: 1
            })
            .then(res => {
              if (res.result == 2) {
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              } else {
                this.$message({
                  message: res.msg,
                  type: "success"
                });
              }
            });
          this.$api.student
            .strategyConfigSetConfig({
              customerAssignConfigList: customerAssignConfigListB,
              type: 1
            })
            .then(res => {
              if (res.result == 2) {
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              } else {
                this.$message({
                  message: res.msg,
                  type: "success"
                });
              }
            });
          this.$api.student
            .strategyConfigSetConfig({
              customerAssignConfigList: customerAssignConfigListB2,
              type: 1
            })
            .then(res => {
              if (res.result == 2) {
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              } else {
                this.$message({
                  message: res.msg,
                  type: "success"
                });
              }
            });
          this.$api.student
            .strategyConfigSetConfig({
              customerAssignConfigList: customerAssignConfigListC,
              type: 1
            })
            .then(res => {
              if (res.result == 2) {
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              } else {
                this.$message({
                  message: res.msg,
                  type: "success"
                });
              }
            });
          this.$api.student
            .strategyConfigSetConfig({
              customerAssignConfigList: customerAssignConfigListD,
              type: 1
            })
            .then(res => {
              if (res.result == 2) {
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              } else {
                this.$message({
                  message: res.msg,
                  type: "success"
                });
              }
            });
        }
      });
    },
    generateRoute() {
      if (this.$route.name) {
        return this.$route;
      }
      return false;
    },
    isActive(route) {
      return route.path === this.$route.path;
    },
    closeSelectedTag(view) {
      this.$store.dispatch("delVisitedViews", this.$route).then(views => {
        if (this.isActive(this.$route)) {
          const latestView = views.slice(-1)[0];
          if (latestView) {
            this.$router.push(latestView);
          } else {
            this.$router.push("/");
          }
        }
      });
    }
  },
  mounted() {
    this.getConfig();
  }
};
</script>

<style lang="scss">
.el-table {
  display: block;
}
.has-gutter tr th {
  text-align: center;
}
.el-table__row td > .cell {
  text-align: center;
}
</style>
<style lang="scss" scoped>
.input-box {
  .input-box-c {
    float: left;
    width: 80%;
  }
}
.el-row {
  margin: 4% 0;
}
.clear {
  clear: both;
}
.group-box {
  width: 80%;
  margin: 0 auto;
  .el-row {
    .el-col-12 {
      text-align: left;
    }
  }
}
.el-row .el-col {
  margin-left: 0;
}
.input-box .tit span {
  font-size: 24px;
  margin-left: 1%;
  font-weight: 700;
  margin-right: 9.7%;
}
.input-box-c-tit {
  margin-top: 5%;
  display: inline-block;
}
</style>
